package com.ruoyi.zhjd.laboratory.modules.asphaltPenetrometer.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
// import com.qzsoft.jeemis.common.utils.Result;
// import com.qzsoft.zhjd.common.utils.ResultUtils;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.zhjd.common.util.ZhjdIotUtils;
import com.ruoyi.zhjd.laboratory.modules.asphaltPenetrometer.entity.AsphaltPenetrometerEntity;
import com.ruoyi.zhjd.laboratory.modules.asphaltPenetrometer.entity.AsphaltPenetrometerResEntity;
import com.ruoyi.zhjd.laboratory.modules.asphaltPenetrometer.service.AsphaltPenetrometerService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

/**
 * 沥青针入度仪
 *
 * @author sx
 * @email
 * @date 2023-07-11 17:18:05
 */
@RestController
@RequestMapping("laboratory/asphaltPenetrometer")
public class AsphaltPenetrometerController {

    @Autowired
    private AsphaltPenetrometerService asphaltPenetrometerService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    //
    public R page(@RequestParam Map<String, Object> params){
        IPage page = asphaltPenetrometerService.queryPage(params);
        return R.ok(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/find/{id}")
    //
    public R find(@PathVariable("id") String id){
		AsphaltPenetrometerEntity asphaltPenetrometer = asphaltPenetrometerService.getInfo(id);
        return R.ok(asphaltPenetrometer);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //
    public R save(@RequestBody AsphaltPenetrometerEntity asphaltPenetrometer){
		asphaltPenetrometerService.saveData(asphaltPenetrometer);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //
    public R update(@RequestBody AsphaltPenetrometerEntity asphaltPenetrometer){
        asphaltPenetrometerService.updateData(asphaltPenetrometer);
        return R.ok();
    }


    /**
     * 删除单个
     */
    @RequestMapping("/delete/{id}")
    //
    public R deleteOne(@PathVariable("id") String id){
        asphaltPenetrometerService.deleteOneData(id);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //
    public R delete(@RequestBody String[] ids){
        asphaltPenetrometerService.deleteData(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 解析数据
     * @param deviceId
     * @param req
     * @return
     */
    @PostMapping("/parsingData/{deviceId}")
    public R parsingData(@PathVariable("deviceId") String deviceId, HttpServletRequest req){
        asphaltPenetrometerService.parsingData(ZhjdIotUtils.dataParsing(req),deviceId);
        return R.ok();
    }

    /**
     * 绑定材料
     */
    @RequestMapping("/changeSample")
    //
    public R changeSample(@RequestBody AsphaltPenetrometerResEntity asphaltPenetrometerResEntity){
        asphaltPenetrometerService.changeSample(asphaltPenetrometerResEntity);
        return R.ok();
    }
}
